package com.dt.app.api.product.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.dt.app.modules.product.entities.ProductMedia;
import com.dt.app.modules.product.vo.ProductMediaBean;
import com.dt.app.api.product.mapper.ProductMediaMapper;
import com.dt.app.api.product.service.IProductMediaService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author 鸿源塔基
 * @since 2024-03-07
 */
@Service
public class ProductMediaServiceImpl extends ServiceImpl<ProductMediaMapper, ProductMedia> implements IProductMediaService {
    public List<ProductMedia> getProductMedias(Integer productId){
        QueryWrapper<ProductMedia> queryWrapper=new QueryWrapper<>();
        queryWrapper.eq("product_id",productId);
        queryWrapper.orderByDesc("seq");
        return this.list(queryWrapper);
    }
    public List<ProductMediaBean> getProductMediaBeans(Integer productId){
        List<ProductMedia> gpms = this.getProductMedias(productId);
        if(gpms==null || gpms.size()<1)return null;
        List<ProductMediaBean> beans=new ArrayList<>();
        for(ProductMedia g:gpms){
            ProductMediaBean b=new ProductMediaBean();
            BeanUtils.copyProperties(g,b);
            b.toInitType();
            beans.add(b);
        }
        return beans;
    }
}